home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2003 September / PC Answers September 2003.iso / Software / trial / MonitorIT 5.2.06 / monitorit_fullsetup.exe / data1.cab / Js / ReportAllFunc.js < prev    next >
Encoding:
JavaScript  |  2003-06-24  |  11.0 KB  |  344 lines

  1. /* ======================================================================
  2. DESC: Common Report Functions for the Administer Operations
  3.  
  4. PLATFORMS: >= MS IE 4.0
  5.  
  6. USAGE NOTES: 
  7. ====================================================================== */
  8. var    RMode = ""; // Mode of Operation, New, Edit, Delete, Lookup
  9. var    RptSelectIdx = 0; // Report select index
  10. var    RptLupRecCount = 0; // Report Lookup record count
  11. var    SALupRecCount = 0; // SA Lookup record count
  12. var    CmpLupRecCount = 0; // Computer Lookup record count
  13. var    ReportRecLength = 7; // Report Lookup record length 
  14. var    CmpRecLth = 7; // Computer Loopkup record length
  15. var    SaRecLth = 6; // Analysis Loopkup record length
  16. var    needSA = true; // Lookup required
  17. var    needComputer = true; // Lookup required
  18. var    needGroup = true; // Lookup required
  19. var    CurSaStoreIdx = 0; // index into Sa Store for current Selected entry
  20. var   CurCmpStoreIdx = 0; // index into Computer Store for Selected Computer Name
  21. var    CidCTab = new Array("","000000","00000","0000","000","00","0","");
  22. var    CidSortArray = null; // Array of sorted Computer IDs
  23. var    BinSearchThresh = (15*CmpRecLth); // Threshold for doing Binary search
  24. var     ReconnectEvent = false;
  25. var     Hp = 82;
  26. var   AR_SaStoreArr = new Array();
  27. var     AR_CmpStoreArr = new Array();
  28. var   AR_RptStoreArr = new Array();
  29.  
  30. /* On Load tell the Comm control to Connect to the Server */
  31. function InitRpmCC_AR() {
  32.     top.MainLoaded = true; // Flag loaded
  33.     initButtonState(); // set initial button state for all buttons
  34.     Hp = parseInt(document.body.RPMHostPort,10);
  35.     RpmCC_AR.Connect(document.body.RPMHostIP,Hp, "");
  36. }
  37. function processRepReconnect() {
  38.     Tid = null;
  39.     if ( RpmCC_AR.IsConnected() ) {
  40.         Tid = setTimeout("processRepConnectionCheck()",30000); // Delay 30 secs then check connection
  41.         return;
  42.     }
  43.     RpmCC_AR.Connect(document.body.RPMHostIP,Hp, ""); 
  44. }
  45. function processRepConnectConfirmed() {
  46.     // Restore Filter and Computer Store    
  47.     if ( ReconnectEvent == false ) {
  48.         RpmCC_AR.GetGlobalSMTP(); // Request Global SMTP address 
  49.         RpmCC_AR.GetGlobalSMTPAuth(); // Request Global SMTP authorization status
  50.         processReportsLookupReset(); // go do Reports Lookup
  51.         ReconnectEvent = true;
  52.     }
  53.     top.Rstatus.Pstat("Connected");
  54.     if ( Tid != null ) {
  55.         clearTimeout(Tid); // stop timeout routine
  56.     }
  57.     Tid = setTimeout("processRepConnectionCheck()",30000); // Delay 30 secs then check connection
  58. }
  59. function processRepConnectionCheck() {
  60.     Tid = null;
  61.     RpmCC_AR.SendKeepAlive("Check");
  62.     Tid = setTimeout("processRepConnectionCheck()",30000); // Delay 30 secs then check connection
  63. }
  64.  
  65. /* On Unload tell the Comm control to Disconnect from the Server */
  66. function DiscoRpmCC_AR() {
  67.     RpmCC_AR.Disconnect();
  68.     top.banner.processStopCommX();
  69.     if ( Tid != null ) {
  70.         clearTimeout(Tid); // stop timeout routine
  71.     }
  72. }
  73.  
  74. /* Initial Reports Lookup Request */
  75. function processReportsLookupReset() {
  76.     /* Make sure Report Store and Report Name combo are flushed */
  77.     lth = document.all.AR_RptSel.length;
  78.     for (i=0; i < lth; ++i)
  79.         document.all.AR_RptSel.remove(0);
  80.  
  81.     AR_RptStoreArr.length = 0;
  82.     RptLupRecCount = 0; // clear Lookup record counter
  83.     processSpecialReportHandling();
  84.     
  85.     if ( RpmCC_AR.AdminReportsLookup("*") ) {
  86.             RMode = "";
  87.             top.Rstatus.Pstat("Unable to start the REPORT LOOKUP request",true);
  88.     }
  89.     else {
  90.             RMode = "LookupReport"; // set Mode of operation
  91.             top.Rstatus.Pstat("One moment while REPORT LOOKUP request completes");
  92.     }
  93. }
  94.  
  95. /* Process Combo Report Name Change Event */
  96. function processReportName() {
  97.     Nobj = document.all.AR_RptSel; // get object
  98.     for (i=0; i < Nobj.length; ++i) {
  99.         if ( Nobj.options[i].selected ) {
  100.             RptSelectIdx = i;
  101.             populateInput(ReportRecLength*i);
  102.             break;
  103.         }
  104.     }
  105. }
  106.  
  107. /* Get SA "Name" string based on SA ID and set Selected Bool */
  108. function getSelectSaName_Desc(Sid) {
  109.     N_D = "";
  110.     for (var i=0; i < AR_SaStoreArr.length; i+=SaRecLth) {
  111.         if ( AR_SaStoreArr[i+1] == Sid ) {
  112.             N_D = AR_SaStoreArr[i];
  113.             CurSaStoreIdx = i; // save index to Store for Selected entry
  114.             break;
  115.         }
  116.     }
  117.     return N_D;
  118. }
  119.  
  120. /* Get Computer "Name : Description" string based on Computer ID and set Selected Bool */
  121. function getSelectCmpName_Desc(Cid) {
  122.     var i;
  123.     N_D = "";
  124.     if ( AR_CmpStoreArr.length < BinSearchThresh ) { // if less than threshold, use For loop
  125.           for ( i=0; i < AR_CmpStoreArr.length; i+=CmpRecLth) {
  126.             if ( AR_CmpStoreArr[i+3] == Cid ) 
  127.                 break;
  128.         }
  129.     }
  130.     else { // set up and do a binary search
  131.         var SAr = new Array();
  132.         sbase = 0; // initial base 
  133.         ecid = parseFloat(Cid); // get numeric value
  134.         sl = CidSortArray.length >>> 1; // initial index is half the length
  135.         while ( true ) { // do binary search
  136.             if ( (sbase+sl) >= CidSortArray.length ) { // don't let index exceed length
  137.                 --sl
  138.                 continue;
  139.             }
  140.             SAr = CidSortArray[sbase+sl].split("~"); 
  141.             ccid = parseFloat(SAr[0]); // numeric Cid
  142.             if ( ecid == ccid )  // if match
  143.                 break;
  144.             if ( sl == 0 ) { // not found 
  145.                 return "";
  146.             }
  147.             nbase = sbase + sl; // create new base
  148.             nsl = sl >>> 1; // halve length of index
  149.             sl = (sl > 2) ? nsl+1 : nsl; // round index when > 2
  150.             if ( ecid > ccid ) // keep searching
  151.                 sbase = nbase;
  152.         }
  153.         i = parseFloat(SAr[1]) * CmpRecLth;
  154.     }
  155.     if ( i < AR_CmpStoreArr.length ) { // if found
  156.          AR_CmpStoreArr[i+5] = 1; // set Selected
  157.         N_D = AR_CmpStoreArr[i] + " / " + AR_CmpStoreArr[i+2];
  158.         CurCmpStoreIdx = i;
  159.     }
  160.     return N_D;
  161. }
  162.  
  163. /* Process Report LOOKUP RECORD Event */
  164. function processReportLookupRecord(Rid,RptName,RptDesc,RptD_T,AIA,CIA,MaxIntv) {
  165.     RNameObj = document.all.AR_RptSel; // Report Name Combo box
  166.     addElementToSelect(RNameObj,RptName);
  167.     // Update Storage
  168.     i = ReportRecLength * RptLupRecCount;
  169.     AR_RptStoreArr[i+0] = RptName;
  170.     AR_RptStoreArr[i+1] = Rid;
  171.     AR_RptStoreArr[i+2] = RptDesc;
  172.     AR_RptStoreArr[i+3] = RptD_T;
  173.     AR_RptStoreArr[i+4] = AIA;
  174.     AR_RptStoreArr[i+5] = CIA;
  175.     AR_RptStoreArr[i+6] = MaxIntv;
  176.     ++RptLupRecCount; // bump record received counter
  177.     ReportRecLength = 7; // length of a Storage record
  178. }
  179.  
  180. /* Process DB Error in Report Lookup Operation */
  181. function processReportOpError() {
  182.     top.Rstatus.Pstat("An error occurred during Report LOOKUP operation",true);
  183.     processResetButton(); // reset
  184. }
  185.  
  186. /* Get Report Name from Store based on Report ID */
  187. function getReportName(RID) {
  188.     RptName = "";
  189.     for (var i=0, j=0; i < AR_RptStoreArr.length; ++j, i+=ReportRecLength) {
  190.         if ( AR_RptStoreArr[i+1] == RID ) {
  191.             RptName = AR_RptStoreArr[i];
  192.             RptSelectIdx = j;
  193.             document.all.AR_RptSel.options[j].selected = "selected";
  194.             break;
  195.         }
  196.     }
  197.     return RptName;
  198. }
  199.  
  200. /* Get Report ID from Store based on Report Name */
  201. function getReportID(RNM) {
  202.     RID = 0;
  203.     for (var i=0, j=0; i < AR_RptStoreArr.length; ++j, i+=ReportRecLength) {
  204.         if ( AR_RptStoreArr[i] == RNM ) {
  205.             RptSelectIdx = j;
  206.             RID = AR_RptStoreArr[i+1];
  207.             break;
  208.         }
  209.     }
  210.     return RID;
  211. }
  212.  
  213. function processSupportAnalysisLookupRecord(Aid,ANme,ADesc,OCXNme,CntArr,OSverArr) {
  214.     var i = SaRecLth * SALupRecCount;
  215.     AR_SaStoreArr[i+0] = ANme;
  216.     AR_SaStoreArr[i+1] = Aid;
  217.     AR_SaStoreArr[i+2] = ADesc;
  218.     AR_SaStoreArr[i+3] = OCXNme;
  219.     AR_SaStoreArr[i+4] = CntArr;
  220.     AR_SaStoreArr[i+5] = OSverArr;
  221.     ++SALupRecCount; // bump record received counter
  222.     SaRecLth = 6; // Storage record length
  223. }
  224.  
  225. /* Process Support Analysis OP Complete Event */
  226. function processSupportAnalysisOpComplete() {
  227.     top.Rstatus.Pstat("Request Completed");
  228.     if (RMode == "TLookupSA") {
  229.         processTemplateLookupComplete();
  230.         return;
  231.     }
  232.     if (SALupRecCount == 0) { // check if any records found
  233.         top.Rstatus.Pstat("No record matches found for Template LOOKUP request",true);
  234.         processResetButton();
  235.     }
  236.     needSA = false;
  237.     if ( needComputer ) {
  238.         CmpLupRecCount = 0; // initialize record counter
  239.         AR_CmpStoreArr.length = 0;
  240.         CidSortArray = new Array(); 
  241.     
  242.         if ( RpmCC_AR.ComputerLookup("*","*") ) {
  243.             top.Rstatus.Pstat("Unable to start the COMPUTER LOOKUP request",true);
  244.             processResetButton();
  245.         }
  246.         else { // waiting for OperationCompleteEvent
  247.               SetCursor("wait");
  248.             C_CommBusy = 1; // set Comm busy flag
  249.             top.Rstatus.Pstat("One moment while COMPUTER LOOKUP request completes");
  250.         }
  251.     }
  252.     else {
  253.           processResetButton();
  254.     }
  255. }
  256.  
  257. /* Process DB Error in Support Analysis Lookup Operation */
  258. function processSupportAnalysisOpError() {
  259.     top.Rstatus.Pstat("An error occurred during Template LOOKUP operation",true);
  260.     processResetButton(); // reset
  261. }
  262.  
  263. /* Process Computer Lookup Op Complete Event */
  264. function processComputerOpComplete() {
  265.     SetCursor("auto");
  266.     top.Rstatus.Pstat("Request Completed");
  267.     if (CmpLupRecCount == 0) { // check if any records found
  268.         top.Rstatus.Pstat("No record matches found for COMPUTER LOOKUP request",true);
  269.         processResetButton();
  270.     }
  271.     needComputer = false;
  272.     CidSortArray.sort();
  273.     if ( needGroup ) {
  274.         GrpLupRecCount = 0; // initialize record counter
  275.         if ( RpmCC_AR.GroupLookup("","","") ) {
  276.             top.Rstatus.Pstat("Unable to start the GROUP LOOKUP request",true);
  277.             processResetButton();
  278.         }
  279.         else { // waiting for OperationCompleteEvent
  280.             C_CommBusy = 1; // set Comm busy flag
  281.             top.Rstatus.Pstat("One moment while GROUP LOOKUP request completes");
  282.         }
  283.     }
  284.     else {
  285.           processResetButton();
  286.     }
  287. }
  288.  
  289. /* Process DB Error in Computer Lookup Operation */
  290. function processComputerOpError() {
  291.     top.Rstatus.Pstat("An error occurred during COMPUTER LOOKUP operation",true);
  292.       SetCursor("auto");
  293.     processResetButton(); // reset
  294. }
  295.  
  296. /* Process Computer LOOKUP RECORD Event */
  297. function processComputerLookupRecord(Cid,Gid,Name,Desc,OSVer) {
  298.      CmpRecLth = 7; // Storage record length
  299.     var i = CmpLupRecCount * CmpRecLth;
  300.     AR_CmpStoreArr[i] = Name;
  301.     AR_CmpStoreArr[i+1] = Gid;
  302.     AR_CmpStoreArr[i+2] = Desc;
  303.     AR_CmpStoreArr[i+3] = Cid;
  304.     AR_CmpStoreArr[i+4] = OSVer;
  305.     AR_CmpStoreArr[i+5] = 0; // Selected Bool
  306.     OSVer = mapOSVer(OSVer); // map OS version to Generic OS types
  307.     AR_CmpStoreArr[i+6] = OSVer;
  308.     var i = CidCTab[Cid.length] + Cid + "~" + CmpLupRecCount;
  309.     CidSortArray[CmpLupRecCount++] = i;
  310. }
  311.  
  312. /* Process Group Lookup Op Complete Event */
  313. function processGroupOpComplete() {
  314.     top.Rstatus.Pstat("Request Completed");
  315.     if (GrpLupRecCount == 0) { // check if any records found
  316.         top.Rstatus.Pstat("No record matches found for GROUP LOOKUP request",true);
  317.     }
  318.     needGroup = false;
  319.     processResetButton();
  320. }
  321.  
  322. function processKeyPress() {
  323.     /* get KeyCode and check if invalid */
  324.     kc = event.keyCode;
  325.     stat = 1; // default to OK
  326.  
  327.     // Keys:   ~            %           [           ]           #           !
  328.     if (kc == 126 ||    kc == 37 || kc == 91 ||    kc == 93 || kc == 35 || kc == 33) { // Not acceptable 
  329.         stat = 0;
  330.     } // Keys:        *           ?
  331.     else if ( (kc == 42 || kc == 63) &&  event.srcElement.name != "AR_Rpt" ) { //Not acceptable
  332.         stat = 0;
  333.     }
  334.     if (stat == 0) { // if Not Acceptable
  335.         event.returnValue=false;
  336.         top.Rstatus.Pstat("Keys ~%*?[]#! are not accepted for this field");    
  337.         alert("Keys ~%*?[]#! are not accepted for this field");    
  338.     }
  339.     else {
  340.         top.Rstatus.Pstat(""); // clear status line
  341.     }
  342. }    
  343.  
  344.